from selenium.webdriver.common.by import By
from base.page_base import BasePage


class CreditApplication(BasePage):
    """额度申请页面"""

    # 1.类属性：元素定位器
    __switch_account = (By.XPATH, "//em[text()='借款账户']")
    __account_apply = (By.LINK_TEXT, "申请额度")
    __amount = (By.ID, "amount_account")
    __detail_msg = (By.NAME, "remark")
    __img_code = (By.ID, "verifycode")
    __confirm_btn = (By.CSS_SELECTOR, ".btn-submit.btn-md")
    # 成功结果文本元素定位
    __success_text = (By.XPATH, '//*[@id="amount_list"]/tr/td[3]')

    # 2.每一步操作步骤方法
    def click_switch_account(self):
        """点击切换账号"""
        self.base_click(self.__switch_account)

    def click_account_apply(self):
        """点击额度申请"""
        self.base_click(self.__account_apply)

    def input_amount(self, amount):
        """输入金额"""
        self.base_input(self.__amount, amount)

    def input_detail_msg(self, msg):
        """输入申请详情"""
        self.base_input(self.__detail_msg, msg)

    def input_img_code(self, img_code):
        """输入图形验证码"""
        self.base_input(self.__img_code, img_code)

    def click_confirm(self):
        """点击确认按钮"""
        self.base_click(self.__confirm_btn)

    # 3.业务方法
    def credit_application(self, amount, msg, img_code="8888"):
        """额度申请"""
        self.click_switch_account()
        self.click_account_apply()
        self.input_amount(amount)
        self.input_detail_msg(msg)
        self.input_img_code(img_code)
        self.click_confirm()


    def get_result_text(self):
        """获取结果文本"""
        return self.fd_element(self.__success_text).text